package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface DishMapper {
    /**
     * 查询分类id下的数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId} ")
    Integer dishCountByCategoryId(Long categoryId);

    /**
     * 增加菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 分页查询全部菜品
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> querySelectPage(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 删除
     * @param ids
     */
    void deleteDishById(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    DishVO findById(Long id);

    @Select("select * from dish where category_id = #{categoryId} ")
    List<Dish> dishByCategoryIdList(Integer categoryId);

    /**
     * 根据id查询菜品并且是起售
     * @param dish
     * @return
     */
    @Select("select * from dish where category_id= #{categoryId}  and status = #{status} ")
    List<Dish> listWithFlavor(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
